package com.ds.common.rocketmq.producer;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;

/**
 * @class: RocketMqConfig
 * @description:
 * @author: fs
 * @create: 2024/1/18 15:19
 **/
public class MqProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void sendMsg(String topic, Object body) {
        Message<Object> build = MessageBuilder.withPayload(body).build();
        rocketMQTemplate.send(topic, build);
    }

    ///**
    // * 发送可靠消息，在事务提交后保证发送成功
    // *
    // * @param topic
    // * @param body
    // */
    //@SecureInvoke
    //public void sendSecureMsg(String topic, Object body, Object key) {
    //    Message<Object> build = MessageBuilder
    //            .withPayload(body)
    //            .setHeader("KEYS", key)
    //            .build();
    //    rocketMQTemplate.send(topic, build);
    //}
}
